<?php
/**
 * Created by PhpStorm.
 * User: liyongyao
 * Date: 2018/8/1
 * Time: 22:42
 */

namespace app\index\controller;

use think\Db;

class MyDb
{
    public function index(){

        $r = Db::name('data')
            ->where('id',1)
            ->find();
        dump($r);


        $list = Db::name('data')
            ->where('id','>',1)
            ->limit(10)
            ->select();
        dump($list);

        $result = Db::name('data')
            ->where('id','>=',1)
            ->limit(10)
            ->select();
        dump($result);

        if($result){
            echo '有数据';
        }else{
            echo '没有数据';
        }

        $rr = Db::name('data')
            ->where('id','in',[2,3,4])
            ->select();
        dump($rr);

        echo '多条件 between like';
        $r2 = Db::name('data')
            ->where('id', 'between', [1,3])
            ->where('name', 'like', '%think%')
            ->select();
        dump($r2);


        echo '多条件';
        $r3 = Db::name('data')
            ->where([
                'id'=>['between', '1,3'],
                'name'=>['like','%thin%']
            ])
            ->select();
        dump($r3);

        echo '多where ,多条件';

        $r4 = Db::name('data')
            ->where('name', 'like', '%think%')
            ->where('id',['in',['1,2,3']],['between','1,5'],'or')
            ->limit(10)
            ->select();

        dump($r4);

        echo '快捷查询';
        $r5 = Db::name('data')
            ->where('id&status','>',0)
            ->limit(10)
            ->select();
        dump($r5);

        echo '快捷查询 or ';
        $r6 = Db::name('data')
            ->where('id|status','>',1)
            ->limit(10)
            ->select();
        dump($r6);

        echo '闭包查询';
        $r7 = Db::name('data')
            ->select(function($query){
                $query->where('name','like','%think%')
                    ->where('id','in','1,2,3')
                    ->select();
            });
        dump($r7);
    }
}